package com.xtravel.discovery.viewholder;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.ViewUtils;
import com.xtravel.R;
import com.xtravel.common.widget.TweetImageView;
import com.xtravel.discovery.activity.LiveDetailActivity;
import com.xtravel.discovery.dto.LiveRecord;

/**
 * Created by memory on 15/12/5.
 */
public final class LiveItemImageViewHolder extends BaseViewHolder<LiveRecord>{
    public TweetImageView imageView;
    public TextView liveLocation;
    public TextView liveName;

    public LiveItemImageViewHolder(Context context, BitmapUtils bitmapUtils, LayoutInflater layoutInflater)
    {
        super(context, bitmapUtils, layoutInflater);
    }

    @Override
    public View getView() {
        View convertView = layoutInflater.inflate(R.layout.live_record_img_item, null);
        this.imageView = (TweetImageView) convertView.findViewById(R.id.record_image);
        this.liveLocation = (TextView)convertView.findViewById(R.id.record_location);
        this.liveName = (TextView)convertView.findViewById(R.id.record_name);
        this.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View imageView) {
                LiveRecord live = (LiveRecord)imageView.getTag();
                Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse(live.liveUrl));
                it.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
                context.startActivity(it);

//                Intent intent = new Intent(context, LiveDetailActivity.class);
//                intent.putExtra("id", live.id);
//                intent.putExtra("liveName", live.name);
//                intent.putExtra("liveCover", live.cover);
//                intent.putExtra("url", live.liveUrl);
//                intent.putExtra("background", live.cover);
//                intent.putExtra("startTime", live.createdTime);
//                intent.putExtra("duration", live.duration);
//                intent.putExtra("userId", live.anchorId);
//                intent.putExtra("userName", live.anchor.nickname);
//                intent.putExtra("userHP", live.anchor.avatarUri);
//                intent.putExtra("location", live.location.address);
//                intent.putExtra("likeCount", live.likedCount);
//                intent.putExtra("imGroupId", live.groupId);
//                intent.putExtra("isLive", live.isLive);
//                context.startActivity(intent);
            }
        });
        convertView.setTag(this);
        return convertView;
    }

    @Override
    public void setValue(LiveRecord live) {
        this.liveName.setText(live.name);
        this.liveLocation.setText(live.location.cityName);
        this.imageView.setImageUrl(bitmapUtils, live.cover);
        this.imageView.setTag(live);
    }
}
